package com.gxa.result;


import lombok.Data;

/**
 * @author zxd
 * @date 2025/5/24
 */
@Data
public class Result<T> {

    //返回的状态码
    private Integer code;

    //返回的提示信息
    private String msg;

    //返回的数据
    private T data;

    //总记录数
    private Long count;


    /**
     * 构建分页成功返回
     * @param data
     * @param count
     * @return
     */
    public static Result buildSuccess(Object data,Long count){
        Result result=new Result();
        result.setCode(0);
        result.setData(data);
        result.setCount(count);
        result.setMsg("操作成功!");
        return result;
    }

    /**
     * 构建普通数据返回的结果
     * @param data
     * @return
     */
    public static Result buildSuccess(Object data){
        return buildSuccess(data,null);
    }

    /**
     * 构建不带返回数据的成功
     * @return
     */
    public static Result buildSuccess(){
        return buildSuccess(null);
    }

    /**
     * 构建失败的结果
     * @param code  状态码
     * @param msg   提示信息
     * @return
     */
    public static Result buildFail(Integer code,String msg){
        Result result=new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

}

